<template>
  <div class="app-container customer-div">
    <div style="margin-top: 40px">

      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
        <el-form-item label="公司：">
          <el-select
            clearable
            v-model="listQuery.fromCompany">
            <el-option
              v-for="item in cList"
              :key="item.id"
              :label="item.fromCompany"
              :value="item.fromCompany">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="牌号：">
          <el-select
                  clearable
                  v-model="listQuery.kingId"
                  filterable
                  remote
                  reserve-keyword
                  placeholder="请输入关键词"
                  :remote-method="remoteMethod2"
                  :loading="loading2">
            <el-option
                    v-for="item in options"
                    :key="item.kingId"
                    :label="item.goodsSn"
                    :value="item.kingId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="仓库：">运联仓
        </el-form-item>
        <el-form-item>
          <el-button
                  @click="handleSearchList()"
                  type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--数据列表-->
    <div class="table-container" style="margin-top:0">
      <el-table
              v-loading="listLoading"
              :data="tableData"
              border
              style="width: 100%;">
        <el-table-column  label="金蝶代码" align="center" prop="kingNumber">
        </el-table-column>
        <el-table-column  label="品名"  align="center">
          <template slot-scope="scope">
              {{scope.row.goodsName}}
          </template>
        </el-table-column>
        <el-table-column  label="牌号"  align="center">
          <template slot-scope="scope">
            {{scope.row.goodsSn}}
          </template>
        </el-table-column>
        <el-table-column  label="可用库存数量" align="center" prop="enableNum">
        </el-table-column>
        <el-table-column  label="实际库存数量" align="center">
          <template slot-scope="scope">
            <span style="color:red">
               {{scope.row.stockNum}}
            </span>
          </template>
        </el-table-column>
        <el-table-column  label="预计待入库数量" align="center" prop="unStockInNum">
        </el-table-column>
        <el-table-column  label="销售在订数量"  align="center">
          <template slot-scope="scope">
              {{scope.row.unSendNum}}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              layout="total, sizes,prev, pager, next,jumper"
              :current-page.sync="listQuery.pageNum"
              :page-size="listQuery.pageSize"
              :page-sizes="[10,15,20]"
              :total="count">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import {warehouseStockList,warehouseList} from '@/api/partner'
  import {goodsList} from '@/api/company'
  import {getCompanyList} from '@/api/order'
  import {formatDate} from '@/utils/date';
  import store from '@/store'
  import { mapGetters } from 'vuex'
  const defaultListQuery={
    pageNum: 1,
    pageSize: 10,
    kingId:null,
    // warehouseId:null,
    warehouseName:'运联仓',
    fromCompany:'',
  };
  export default {
    name: "index",
    data(){
      return {
        listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
        tableData: [],
        count: 0,
        listLoading: false,
        roles:store.getters.roles ? store.getters.roles : [],
        wList:[],
        options:[],
        loading2:false,
        cList:[]
      }
    },
    computed: {
      ...mapGetters([
        'name',
        'mobile',
        'userId'
      ]),

    },
    created() {
      this.getList();
      this.getWarehouseList();
      this.getCList();
    },
    filters: {
      formatCreateTime(time) {
        if(time){
          let date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
        }else{
          return '--'
        }
      },
    },
    methods:{
      getCList(){
        getCompanyList().then((res)=>{
          this.cList = res
        })
      },
      //获取商品列表
      remoteMethod2(query) {
        if (query !== '') {
          this.loading2 = true;
          goodsList({keywords:query}).then((res)=>{
            this.options = res.list;
            this.loading2 = false;
          }).catch(()=>{
            this.loading2 = false;
          });
        } else {
          this.options = [];
        }
      },
      //获取仓库下拉选项
      getWarehouseList(){
        warehouseList().then((res)=>{
          this.wList = res;
        })
      },

      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },

      handleSearchList(){
        this.listQuery.pageNum = 1;
        this.getList();
      },

      //获取列表
      getList() {
        this.listLoading = true;
        warehouseStockList(this.listQuery).then(response => {
          this.tableData = response.list;
          this.count = response.count;
          this.listLoading = false;
        }).catch(()=>{
          this.listLoading = false;
        });
      },

    },
  }
</script>

<style scoped lang="scss">

  .upload-div{
    text-align: center;
    position:relative;
    #upload{

      opacity: 0;
      position: absolute;
      z-index: 1;
      width:154px;
      height:40px
    }
  }
</style>
